package com.dtguai.app.util;

import javax.servlet.http.HttpServletRequest;

/**
   * @author: guoLiang
   * @date：2018-09-29 03:46:03
   * @类描述：
   * @项目名称：tellhow
   * @包名： com.tellhow.app.util
   * @类名称：IpUtils
   * @version v1.0
   * @see 
   * @bug 
   * @Copyright guoLiang
   * @mail 123086461@qq.com
   */
public class IpUtils {
	private static final String UNKNOWN = "unknown";

	public static String getIpAddress(HttpServletRequest request) {
		String ip = request.getHeader("X-FORWARDED-FOR");
		if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
			ip = request.getHeader("HTTP_CLIENT_IP");
		}
		if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
			ip = request.getHeader("HTTP_X_FORWARDED_FOR");
		}
		if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
		}
		return ip;
	}

}
